package com.example.administrator.jingpingou.activity;

import android.app.FragmentTransaction;
import android.content.Intent;
import android.graphics.Color;
import android.support.annotation.Nullable;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.jingpingou.R;
import com.example.administrator.jingpingou.adapter.NextThemeAdapter;
import com.example.administrator.jingpingou.bean.NextThemeBean;
import com.example.administrator.jingpingou.config.NetConfig;
import com.example.administrator.jingpingou.fragment.NextThemeFragmentOne;
import com.example.administrator.jingpingou.fragment.NextThemeFragmentTwo;
import com.google.gson.Gson;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

public class NextThemeActivity extends AppCompatActivity {
    private NextThemeAdapter mAdapter;
    private List<NextThemeBean.DataBean> mData;
//    private int currentPage=1;

    private String zid;
    private ImageView mImageBack,mIamgeChange;

    private View view;
    private TextView mTextTitle;

    private boolean flag=true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_next_theme);
        Intent intent = getIntent();
        zid = intent.getStringExtra("zid");
        initView();
        setData();
        setListener();
    }

    private void setData() {
        FragmentManager manager = getSupportFragmentManager();
        android.support.v4.app.FragmentTransaction tran= manager.beginTransaction();
        Fragment fragmentOne = new NextThemeFragmentOne();
        tran.replace(R.id.fl_ac_next_theme,fragmentOne);
        Bundle bundle=new Bundle();
        bundle.putString("zid",zid);
        fragmentOne.setArguments(bundle);
        tran.addToBackStack(null);
        tran.commit();
    }

    private void setListener() {
        mImageBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mIamgeChange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (flag){
                    flag=!flag;
                   FragmentManager manager = getSupportFragmentManager();
               android.support.v4.app.FragmentTransaction tran= manager.beginTransaction();
                    Fragment fragmentOne = new NextThemeFragmentOne();
                tran.replace(R.id.fl_ac_next_theme,fragmentOne);
                    Bundle bundle=new Bundle();
                    bundle.putString("zid",zid);
                    fragmentOne.setArguments(bundle);
                tran.addToBackStack(null);
                    tran.commit();
                }else{
                    flag=!flag;
                    FragmentManager manager = getSupportFragmentManager();
               android.support.v4.app.FragmentTransaction tran= manager.beginTransaction();
                    Fragment fragmenTwo = new NextThemeFragmentTwo();
                    tran.replace(R.id.fl_ac_next_theme,fragmenTwo);
                    Bundle bundle=new Bundle();
                    bundle.putString("zid",zid);
                    fragmenTwo.setArguments(bundle);
                tran.addToBackStack(null);
                tran.commit();
                   }
            }
        });
    }


    private void initView() {
        mIamgeChange = (ImageView) findViewById(R.id.iv_activity_next_theme_change);
        mImageBack = (ImageView) findViewById(R.id.iv_activity_next_theme_back);

        view = findViewById(R.id.v_next_activity_theme);
        mTextTitle = (TextView) findViewById(R.id.tv_activity_text_theme_title);
//        mRecyclerView.addItemDecoration(new ItemDecoration(5));
//
    }
}
